
global user "`c(username)'"
global dirdata "C:\Users\\$user\Dropbox\CCT BJP\data"
global dir1  "$dirdata\Final data"
global dir2  "$dirdata\Results\graphs"
global dir3  "$dirdata\Results\"
cd "$dir2"

use "$dir1\pooled_hh.dta", clear
keep if tau>-5  
g age=age_m if hhmale==0
replace age=age_p if hhmale==1
g spanish=spanish_m if hhmale==0
replace spanish=spanish_p if hhmale==1

g Post=tau>=0

 






global covs1 "age_m spanish_m schooling_m age spanish schooling hhmale urban np nchild5 age_sac  c.age_sac#i.year c.np#i.year  i.departamento#i.year i.year"
global covs2 "age spanish  schooling age_p spanish_p schooling_p hhmale urban np nchild5 age_sac  c.age_sac#i.year c.np#i.year i.departamento#i.year  i.year"
 
local spec1  Post i.min_schooling  $covs1  
local spec2  Post i.min_schooling  $covs2  

local sample1 "(min_schooling>=1 & min_schooling<9) "

g coef=.
g std=.
g x=.


preserve

forval x=10(10)90 {
g work_m_`x'=(w_hoursw_m>`x')
areg work_m_`x'  `spec1' [w=factor] if `sample1', a(departamento) cluster(municipio)
matrix V=e(V)
replace coef=_b[Post] in `x'
replace std=_se[Post] in `x'
replace x=`x' in `x'
drop work_m_`x'
}

g work_m_0=(w_hoursw_m>0)
areg work_m_0  `spec1' [w=factor] if `sample1', a(departamento) cluster(municipio)
replace coef=_b[Post] in 11
replace std=_se[Post] in 11
replace x=0 in 11

keep coef std x
sort x
drop if coef==.

g ub=coef+1.96*std
g lb=coef-1.96*std
g OLS=_b[Post]
tw line coef x, sort || rline ub lb x, sort  || line OLS x, sort  lcolor(black) yline(0) ytitle(Prob. , size(small)) legend(order(1 "Coeff." 2 "95% CI" 3 "Effects on P(hours>0)")  size(small)) xtitle("Hours/Week (h)") title("A: Effects on Pr(hours>h) - Females", size(msmall)) saving(a1, replace) graphregion(color(white)) ylabel(,labsize(small)) xlabel(#10, labsize(small))
restore


preserve
hist w_hoursw_m if w_hoursw_m<=90, graphregion(color(white)) xtitle(Hours/week, size(small)) bin(11) bfcolor(none) blcolor(navy) title("C-Distribution of work hours(Females)", size(msmall)) saving(a3, replace) ylabel(,labsize(small)) xlabel(#10, labsize(small)) frac
restore



preserve

forval x=10(10)90 {
g work_p_`x'=(w_hoursw_p>`x')
areg work_p_`x'  `spec1' [w=factor] if `sample1', a(departamento) cluster(municipio)
matrix V=e(V)
replace coef=_b[Post] in `x'
replace std=_se[Post] in `x'
replace x=`x' in `x'
drop work_p_`x'
}

g work_p_0=(w_hoursw_p>0)
areg work_p_0  `spec2' [w=factor] if `sample1', a(departamento) cluster(municipio)
replace coef=_b[Post] in 11
replace std=_se[Post] in 11
replace x=0 in 11

keep coef std x
sort x
drop if coef==.

g ub=coef+1.96*std
g lb=coef-1.96*std
g OLS=_b[Post]
tw line coef x, sort || rline ub lb x, sort  || line OLS x, sort  lcolor(black) yline(0) ytitle(Prob. , size(small)) legend(order(1 "Coeff." 2 "95% CI" 3 "Effects on P(hours>0)")  size(small)) xtitle("Hours/Week (h)") title("B-Effects on Pr(hours>h)-Males", size(msmall)) saving(a2, replace) graphregion(color(white)) ylabel(,labsize(small)) xlabel(#10, labsize(small))
restore


preserve
hist w_hoursw_p if w_hoursw_p<=90 , graphregion(color(white)) xtitle(Hours/week, size(small)) bin(11) bfcolor(none) blcolor(navy) title("D-Distribution of work hours (Males)", size(msmall)) saving(a4, replace) ylabel(,labsize(small)) xlabel(#10, labsize(small)) frac
restore


grc1leg  a1.gph a2.gph , cols(2) ycommon xcommon graphregion(color(white)) saving(a1, replace)

gr combine  a3.gph a4.gph , cols(2) xcommon ycommon graphregion(color(white)) saving(a2, replace)
gr combine a1.gph a2.gph , cols(1) xcommon graphregion(color(white)) 
gr export Figure7.eps, replace

